package org.example.Thread02;

import java.util.concurrent.atomic.AtomicInteger;

public class Dome_Thread01 {
    public static void main(String[] args) throws InterruptedException {
        //基于CAS的原子类
        AtomicInteger atomicInteger=new AtomicInteger();
        //创建两个线程，分别自增50000次
        Thread t1 = new Thread(()->{
            for(int i=0;i<50000;i++){
                atomicInteger.getAndIncrement();
            }
        });
        t1.start();
        Thread t2 = new Thread(()->{
            for(int i=0;i<50000;i++){
                atomicInteger.getAndIncrement();
            }
        });
        t2.start();
        //等待两个线程结束
        t1.join();
        t2.join();
        System.out.println(atomicInteger);
    }
}
